<?php

namespace app\admin\services;

use app\admin\model\BannerAddressModel;

class BannerAddressService extends BaseService
{
    public function list($param = [], $field = "*")
    {
        $bannerAddressModel = BannerAddressModel::makeInstance();
        $list = $bannerAddressModel->list($param, $field);
        return $list;
    }

    public function save($param = [], $id = 0)
    {
        $bannerAddressModel = BannerAddressModel::makeInstance();
        if ($id == 0) {
            $param['create_time'] = time();
            $param['update_time'] = time();
            $param['create_id'] = session('aid');
            $param['update_id'] = session('aid');
            $res = $bannerAddressModel->mInsert($param);
        } else {
            $param['update_time'] = time();
            $param['update_id'] = session('aid');
            $res = $bannerAddressModel->mUpdate($param, $id);
        }
        return $res;
    }

    public function getInfoById($id, $param = [])
    {
        $bannerAddressModel = BannerAddressModel::makeInstance();
        return $bannerAddressModel->getInfoById($id, $param);
    }

    /**
     * 获取有效数据
     */
    public function getOpenData($field = "*")
    {
        $bannerAddressModel = BannerAddressModel::makeInstance();
        $list = $bannerAddressModel->getDatasByWhere([
            'is_delete' => 1,
            'status' => 1
        ],$field)->toArray();
        return array_column($list,null,'id');
    }
}